package com.uk.ui.kontrata;

import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Window.Notification;

public class KontrataSearchView extends Panel {

	private KontrataPanel kontrataPanel;

	private TextField emri;
	private TextField mbiemri; 
	
	public KontrataSearchView(KontrataPanel kontrataPanel){
		this.kontrataPanel = kontrataPanel;
		addStyleName("view");
		setSizeFull();
		
		FormLayout formLayout = new FormLayout();
		setContent(formLayout);
		
		emri = new TextField("Emri");
		mbiemri = new TextField("Mbiemri");
		Button search = new Button("Kerko");
		
		search.addListener(new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				performSearch();
				
			}
		});
		
		addComponent(emri);
		addComponent(mbiemri);
		addComponent(search);
		
		
	}
	
	
	private void performSearch(){
		String emriVal = (String) emri.getValue();
		String mbiemriVal = (String) mbiemri.getValue();
		
		if ((emriVal == null || "".equals(emriVal)) && 
				(mbiemriVal == null || "".equals(mbiemriVal))){
			getWindow().showNotification("Emri dhe mbiemri nuk mund te jene njekohesisht bosh", Notification.TYPE_WARNING_MESSAGE);
		}
		 
		emriVal = "%" + emriVal + "%";
		mbiemriVal = "%" + mbiemriVal + "%";
		
		kontrataPanel.search(emriVal,mbiemriVal);
		
	}
}
